package com.app.micaihu.view.main.topic.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.topic.SendImageBean;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.LogUtils;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

import java.util.List;

/**
 * 显示发表图片的适配器
 * 
 * @author linkai
 * 
 */
public class SendImageGridAdapter extends AppBaseAdapter<String> {
	private int width;
	public SendImageGridAdapter(List<String> list,Context context,float space){
		super(list, context);
		this.width = (int) ViewSizeUtils.changeView30Per(context, 3.0f, space);
	}

	public SendImageGridAdapter(List<String> list, Context context) {
		super(list, context);

		this.width = (int) ViewSizeUtils.changeView30Per(context, 0f, 30f);

	}


	@Override
	public View creatView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_9_img, null);
			viewHolder.image = (CustomImageView) convertView.findViewById(R.id.image);
			ViewSizeUtils.changeViewWH(viewHolder.image, this.width, this.width);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		LoadImageUtils.getInstance().loadImage(viewHolder.image,list.get(position));

		return convertView;
	}

	private class ViewHolder {
		CustomImageView image;
	}

	/**
	 * 返回当前的list
	 * @return this.list
	 */
	public List<String> getList(){
		return this.list;
	}


	/**
	 * 更新list
	 * @param list
     */
	public void setList(List<String> list){
		this.list = list;

	}

}
